package com.scujcc.parameterbinding;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.convert.DataSizeUnit;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.stereotype.Component;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

//第三方bean属性绑定
@Data
@Component
@Validated
@ConfigurationProperties(prefix = "server")
public class ServerConfig {
    String ipAddress;
    //添加校验规则
    @Max(value = 100,message = "最大值不能超过100")
    @NotNull
    Integer port;
    Long timeout;
    //设置时间单位
    @DurationUnit(ChronoUnit.MICROS)
    Duration serverTimeout;
    //若配置文件中未设置单位，使用@DataSizeUnit设置文件单位
//    @DataSizeUnit(DataUnit.MEGABYTES)
    DataSize dataSize;

}
